import React, { Component } from "react";
// 引入prop-types，用于做props的类型检查
import PropTypes, { string, number, oneOf, oneOfType } from "prop-types";

/*
any
array
arrayOf
bigint
bool
checkPropTypes
element
elementType
exact
func
instanceOf
node
number
object
objectOf
oneOf
oneOfType
resetWarningCache
shape
string
symbol
*/

class Child extends Component {
  // static defaultProps = {};
  static propTypes = {
    // name: PropTypes.string,
    // age: PropTypes.number,

    // .isRequired表示必填项
    name: string.isRequired,
    age: number,
    // 几个值中的其中一个
    size: oneOf(["large", "middle", "small"]),
    // 几个类型中的其中一个
    age2: oneOfType([string, number]),
  };

  render() {
    console.log(PropTypes);
    return (
      <>
        <div>child子组件</div>
        <div>name: {this.props.name}</div>
        <div>age: {this.props.age}</div>
      </>
    );
  }
}
// Child.propTypes = {}

const App = () => {
  return (
    <>
      <h2>props的数据类型</h2>
      <Child name="rose" age={20} />
    </>
  );
};

export default App;
